<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Data Driven Substructure: pdf.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Data Driven Substructure
   
   </div>
   <div id="projectbrief">A library for carrying out Multivariate Kernel Smoothing--designed to be fast and flexible for large data processing.</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">pdf.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef __PDF__</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define __PDF__</span>
<a name="l00003"></a>00003 <span class="preprocessor"></span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;tensor.h&quot;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &quot;mtrand.h&quot;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00007"></a>00007 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="keyword">using namespace </span>std;
<a name="l00010"></a>00010 
<a name="l00019"></a><a class="code" href="classPDF.html">00019</a> <span class="keyword">class </span><a class="code" href="classPDF.html" title="PDF functions.">PDF</a>{
<a name="l00020"></a>00020  <span class="keyword">public</span>:
<a name="l00021"></a><a class="code" href="classPDF.html#a17f3b7c7818566cb7df35ace0235999b">00021</a>   <a class="code" href="classPDF.html#a17f3b7c7818566cb7df35ace0235999b">PDF</a>(){valid=<span class="keyword">false</span>;}
<a name="l00025"></a>00025 
<a name="l00026"></a>00026   <span class="keywordtype">double</span> operator()(<span class="keyword">const</span> valarray&lt;double&gt;&amp; ntuple, <span class="keywordtype">double</span>* err=NULL) <span class="keyword">const</span>;
<a name="l00030"></a>00030 
<a name="l00031"></a>00031   <span class="keywordtype">double</span> FullEvaluate(<span class="keyword">const</span> valarray&lt;double&gt;&amp; ntuple, <span class="keywordtype">double</span>* err, 
<a name="l00032"></a>00032                       valarray&lt;double&gt;&amp; grad_output) <span class="keyword">const</span>;
<a name="l00035"></a>00035 
<a name="l00036"></a>00036   <span class="keywordtype">bool</span> Write(<span class="keyword">const</span> <span class="keywordtype">char</span>* output) <span class="keyword">const</span>;
<a name="l00038"></a>00038 
<a name="l00039"></a>00039   <span class="keywordtype">bool</span> Read(<span class="keyword">const</span> <span class="keywordtype">char</span>* input);
<a name="l00041"></a>00041 
<a name="l00042"></a><a class="code" href="classPDF.html#a469c916500cafce4b3ad612180b59231">00042</a>   <span class="keywordtype">bool</span> IsValid()<span class="keyword"> const</span>
<a name="l00043"></a>00043 <span class="keyword">  </span>{<span class="keywordflow">return</span> valid;}
<a name="l00045"></a>00045 
<a name="l00046"></a>00046   <span class="keywordtype">int</span> Rank()<span class="keyword"> const</span>
<a name="l00047"></a>00047 <span class="keyword">  </span>{<span class="keywordflow">return</span> data.Rank();}
<a name="l00048"></a>00048 
<a name="l00049"></a>00049   <span class="keyword">friend</span> ostream&amp; operator&lt;&lt;(ostream&amp;, <span class="keyword">const</span> <a class="code" href="classPDF.html" title="PDF functions.">PDF</a>&amp;);
<a name="l00051"></a>00051 
<a name="l00052"></a>00052   <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classDataSet.html" title="a class to store multi-dimensional data">DataSet</a>;
<a name="l00054"></a>00054 
<a name="l00055"></a>00055   <a class="code" href="classTensor.html">Tensor&lt;double&gt;</a> <a class="code" href="classDataSet.html#a4a82950e47b524eb2e242e00e17eb2d4" title="to store multidimensional info">data</a>;
<a name="l00057"></a>00057 
<a name="l00061"></a><a class="code" href="classPDF.html#a8bade35ad19857caa9cd7a33b790aaed">00061</a>   <span class="keyword">enum</span> <a class="code" href="classPDF.html#a8bade35ad19857caa9cd7a33b790aaed">Projection</a>{
<a name="l00062"></a>00062     KEEP, INTEGRATE
<a name="l00063"></a>00063   };
<a name="l00064"></a>00064 
<a name="l00065"></a>00065   <a class="code" href="classPDF.html" title="PDF functions.">PDF</a> Project(<span class="keyword">const</span> valarray&lt;Projection&gt; input) <span class="keyword">const</span>;
<a name="l00067"></a>00067 
<a name="l00071"></a><a class="code" href="classPDF.html#aa0feee39b27d3f506bf0b39018b9922a">00071</a>   <span class="keyword">enum</span> <a class="code" href="classPDF.html#aa0feee39b27d3f506bf0b39018b9922a">MC_Flag</a>{
<a name="l00072"></a>00072     INPUT, OUTPUT
<a name="l00073"></a>00073   };
<a name="l00074"></a>00074 
<a name="l00085"></a>00085   <span class="keyword">class </span>MC_Event;
<a name="l00086"></a>00086 
<a name="l00095"></a>00095   <span class="keyword">class </span>MC_Generator;
<a name="l00096"></a>00096 
<a name="l00097"></a>00097   MC_Generator Generator(<span class="keyword">const</span> valarray&lt;MC_Flag&gt;&amp; flag_) <span class="keyword">const</span>;
<a name="l00099"></a>00099 
<a name="l00100"></a>00100 
<a name="l00101"></a>00101   valarray&lt;double&gt; one_over_width;
<a name="l00103"></a>00103 
<a name="l00104"></a>00104   valarray&lt;double&gt; width;
<a name="l00106"></a>00106 
<a name="l00107"></a>00107   valarray&lt;double&gt; min;
<a name="l00109"></a>00109 
<a name="l00110"></a>00110   valarray&lt;double&gt; max;
<a name="l00112"></a>00112 
<a name="l00113"></a>00113   valarray&lt;int&gt; nbins;
<a name="l00115"></a>00115 
<a name="l00116"></a>00116  <span class="keyword">private</span>:
<a name="l00117"></a>00117   
<a name="l00118"></a>00118   <a class="code" href="classTensor.html">Tensor&lt;double&gt;</a> data_bias;
<a name="l00120"></a>00120 
<a name="l00121"></a>00121   <a class="code" href="classTensor.html">Tensor&lt;double&gt;</a> data_var;
<a name="l00123"></a>00123 
<a name="l00124"></a>00124   <a class="code" href="classTensor.html">Tensor&lt;double&gt;</a> data_err;
<a name="l00126"></a>00126 
<a name="l00127"></a>00127   <span class="keywordtype">bool</span> valid;
<a name="l00129"></a>00129 
<a name="l00130"></a>00130   <span class="keywordtype">double</span> min_err;
<a name="l00136"></a>00136 
<a name="l00137"></a>00137   <span class="keywordtype">void</span> Initialize(<span class="keywordtype">int</span> nvar, <span class="keyword">const</span> <span class="keywordtype">double</span>* min, <span class="keyword">const</span> <span class="keywordtype">double</span>* max,
<a name="l00138"></a>00138                   <span class="keyword">const</span> <span class="keywordtype">double</span>* precision_=NULL, <span class="keyword">const</span> <span class="keywordtype">double</span> min_err_=0);
<a name="l00141"></a>00141 
<a name="l00142"></a>00142   <span class="comment">//private inline functions</span>
<a name="l00143"></a>00143   <span class="keyword">inline</span> <span class="keywordtype">double</span> GetBinCenter(<span class="keywordtype">int</span> index, <span class="keywordtype">int</span> bin) <span class="keyword">const</span>;
<a name="l00145"></a>00145   
<a name="l00146"></a>00146   <span class="keyword">inline</span> valarray&lt;double&gt; GetBinCenter(<span class="keyword">const</span> valarray&lt;int&gt;&amp; index) <span class="keyword">const</span>;
<a name="l00149"></a>00149 
<a name="l00150"></a>00150   <span class="keyword">inline</span> <span class="keywordtype">int</span> GetBin_helper(<span class="keywordtype">double</span> value, <span class="keywordtype">int</span> bin) <span class="keyword">const</span>;
<a name="l00152"></a>00152 };
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 <span class="comment">//more detailed implementation of the MC_Generator class</span>
<a name="l00156"></a>00156 <span class="keyword">class </span>PDF::MC_Generator{
<a name="l00157"></a>00157  <span class="keyword">public</span>:
<a name="l00158"></a>00158   
<a name="l00159"></a>00159   MC_Generator(<span class="keyword">const</span> valarray&lt;MC_Flag&gt;&amp; flag_, <span class="keyword">const</span> <a class="code" href="classPDF.html" title="PDF functions.">PDF</a>* pdf_);
<a name="l00161"></a>00161   
<a name="l00162"></a>00162   vector&lt;MC_Event&gt; Generate(<span class="keyword">const</span> valarray&lt;double&gt;&amp; input, <span class="keywordtype">int</span> nevt=1000) <span class="keyword">const</span>;
<a name="l00164"></a>00164 
<a name="l00165"></a>00165   vector&lt;MC_Event&gt; GenerateGrad(<span class="keyword">const</span> valarray&lt;double&gt;&amp; input, <span class="keywordtype">int</span> nevt=1000) <span class="keyword">const</span>;
<a name="l00167"></a>00167 
<a name="l00168"></a>00168   vector&lt;MC_Event&gt; Generate(<span class="keywordtype">int</span> nevt=1000)<span class="keyword"> const</span>
<a name="l00169"></a>00169 <span class="keyword">    </span>{
<a name="l00170"></a>00170       <span class="keywordflow">return</span> Generate(valarray&lt;double&gt;(), nevt);
<a name="l00171"></a>00171     }
<a name="l00173"></a>00173 
<a name="l00174"></a>00174   vector&lt;MC_Event&gt; GenerateFast(<span class="keyword">const</span> valarray&lt;double&gt;&amp; input, <span class="keywordtype">int</span> nevt=1000) 
<a name="l00175"></a>00175     <span class="keyword">const</span>;
<a name="l00177"></a>00177 
<a name="l00178"></a>00178   vector&lt;MC_Event&gt; GenerateFast(<span class="keywordtype">int</span> nevt=1000)<span class="keyword"> const</span>
<a name="l00179"></a>00179 <span class="keyword">    </span>{
<a name="l00180"></a>00180       <span class="keywordflow">return</span> Generate(valarray&lt;double&gt;(), nevt);
<a name="l00181"></a>00181     }
<a name="l00183"></a>00183 
<a name="l00184"></a>00184   vector&lt;MC_Event&gt; GenerateFull(<span class="keyword">const</span> valarray&lt;double&gt;&amp; input) <span class="keyword">const</span>;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188                          
<a name="l00189"></a>00189  <span class="keyword">private</span>:
<a name="l00190"></a>00190   valarray&lt;MC_Flag&gt; flag;
<a name="l00192"></a>00192   
<a name="l00193"></a>00193   <span class="keyword">const</span> <a class="code" href="classPDF.html" title="PDF functions.">PDF</a>* pdf;
<a name="l00195"></a>00195 
<a name="l00196"></a>00196   <span class="keywordtype">int</span> input_size;
<a name="l00198"></a>00198   
<a name="l00199"></a>00199   vector&lt;int&gt; index;
<a name="l00201"></a>00201 
<a name="l00202"></a>00202   <span class="keyword">static</span> MTRand_int32 irand;
<a name="l00204"></a>00204   
<a name="l00205"></a>00205 };
<a name="l00206"></a>00206 
<a name="l00207"></a>00207 
<a name="l00208"></a>00208 <span class="comment">//more detailed implementation of the MC_Event class</span>
<a name="l00209"></a>00209 <span class="keyword">class </span>PDF::MC_Event{
<a name="l00210"></a>00210  <span class="keyword">public</span>:
<a name="l00211"></a>00211   
<a name="l00212"></a>00212   <span class="keywordtype">double</span> err;
<a name="l00214"></a>00214 
<a name="l00215"></a>00215   <span class="keywordtype">double</span> weight;
<a name="l00217"></a>00217 
<a name="l00218"></a>00218   valarray&lt;double&gt; extra;
<a name="l00220"></a>00220 
<a name="l00221"></a>00221   valarray&lt;double&gt; value;
<a name="l00223"></a>00223   
<a name="l00224"></a>00224   MC_Event(<span class="keyword">const</span> valarray&lt;double&gt;&amp; value_, 
<a name="l00225"></a>00225            <span class="keywordtype">double</span> err_, <span class="keywordtype">double</span> weight_):
<a name="l00226"></a>00226   value(value_), err(err_), weight(weight_) {}
<a name="l00228"></a>00228 
<a name="l00229"></a>00229   <span class="keywordtype">void</span> SetExtra(<span class="keyword">const</span> valarray&lt;double&gt;&amp; extra_)
<a name="l00230"></a>00230   {
<a name="l00231"></a>00231     extra=extra_;
<a name="l00232"></a>00232   }
<a name="l00233"></a>00233   
<a name="l00234"></a>00234   valarray&lt;double&gt;&amp; GetExtra()
<a name="l00235"></a>00235   {
<a name="l00236"></a>00236     <span class="keywordflow">return</span> extra;
<a name="l00237"></a>00237   }
<a name="l00238"></a>00238 
<a name="l00239"></a>00239   <span class="keywordtype">double</span> operator[](<span class="keywordtype">int</span> i)<span class="keyword"> const</span>
<a name="l00240"></a>00240 <span class="keyword">  </span>{
<a name="l00241"></a>00241     assert(i&gt;=0 &amp;&amp; i&lt;value.size());
<a name="l00242"></a>00242     <span class="keywordflow">return</span> value[i];
<a name="l00243"></a>00243   }
<a name="l00245"></a>00245 
<a name="l00246"></a>00246   
<a name="l00247"></a>00247 
<a name="l00248"></a>00248 };
<a name="l00249"></a>00249 
<a name="l00250"></a>00250 
<a name="l00251"></a><a class="code" href="classPDF.html#ae023f48bd7f9297539dcaba506c8f5a8">00251</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classPDF.html#ae023f48bd7f9297539dcaba506c8f5a8" title="compute value centered at bin (a particular dimension)">PDF::GetBinCenter</a>(<span class="keywordtype">int</span> index, <span class="keywordtype">int</span> bin)<span class="keyword"> const</span>
<a name="l00252"></a>00252 <span class="keyword"></span>{
<a name="l00253"></a>00253   <span class="comment">//DEBUG</span>
<a name="l00254"></a>00254   <span class="comment">/*</span>
<a name="l00255"></a>00255 <span class="comment">  cout&lt;&lt;&quot;GetBin small input : &quot;&lt;&lt;index&lt;&lt;&quot;,&quot;&lt;&lt;bin&lt;&lt;endl;</span>
<a name="l00256"></a>00256 <span class="comment">  cout&lt;&lt;&quot;GetBin small output : &quot;&lt;&lt;(index+0.5)*(max[bin]-min[bin])&lt;&lt;&quot;,&quot;&lt;&lt;min[bin]&lt;&lt;endl;</span>
<a name="l00257"></a>00257 <span class="comment">  */</span>
<a name="l00258"></a>00258 
<a name="l00259"></a>00259   <span class="keywordflow">return</span> (index+0.5)*width[bin]+min[bin];
<a name="l00260"></a>00260 }
<a name="l00261"></a>00261 
<a name="l00262"></a><a class="code" href="classPDF.html#a6f799c70b3922ad8598d54c975fb3b9b">00262</a> <span class="keyword">inline</span> valarray&lt;double&gt; <a class="code" href="classPDF.html#ae023f48bd7f9297539dcaba506c8f5a8" title="compute value centered at bin (a particular dimension)">PDF::GetBinCenter</a>(<span class="keyword">const</span> valarray&lt;int&gt;&amp; index)<span class="keyword"> const</span>
<a name="l00263"></a>00263 <span class="keyword"></span>{
<a name="l00264"></a>00264   assert(index.size()==data.rank);
<a name="l00265"></a>00265   valarray&lt;double&gt; result(data.rank);
<a name="l00266"></a>00266   
<a name="l00267"></a>00267   <span class="comment">//grab central value of bin in each dimension</span>
<a name="l00268"></a>00268   <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;result.size(); i++)
<a name="l00269"></a>00269     {
<a name="l00270"></a>00270       result[i]=GetBinCenter(index[i], i);
<a name="l00271"></a>00271     }
<a name="l00272"></a>00272 
<a name="l00273"></a>00273   <span class="keywordflow">return</span> result;
<a name="l00274"></a>00274 }
<a name="l00275"></a>00275 
<a name="l00276"></a>00276 
<a name="l00277"></a><a class="code" href="classPDF.html#a15de6045a0fc1f57a00708e27ab1634a">00277</a> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classPDF.html#a15de6045a0fc1f57a00708e27ab1634a" title="return bin given value">PDF::GetBin_helper</a>(<span class="keywordtype">double</span> value, <span class="keywordtype">int</span> bin)<span class="keyword"> const</span>
<a name="l00278"></a>00278 <span class="keyword"></span>{
<a name="l00279"></a>00279   <span class="keywordtype">double</span> temp_bin= (value-min[bin])*one_over_width[bin];
<a name="l00280"></a>00280   <span class="comment">//if value is in underflowed, go to the zeroth bin</span>
<a name="l00281"></a>00281   <span class="keywordflow">if</span>(temp_bin&lt;0) <span class="keywordflow">return</span> 0;
<a name="l00282"></a>00282   
<a name="l00283"></a>00283   <span class="comment">//if value is overflowed, go to the last bin</span>
<a name="l00284"></a>00284   <span class="keywordflow">if</span>(temp_bin&gt;=nbins[bin]) <span class="keywordflow">return</span> nbins[bin]-1;
<a name="l00285"></a>00285   <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span>(temp_bin);
<a name="l00286"></a>00286 }
<a name="l00287"></a>00287 
<a name="l00288"></a>00288 
<a name="l00289"></a>00289 <span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Sep 12 2013 17:12:58 for Data Driven Substructure by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
